package com.xhcl.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xhcl.common.annotation.Log;
import com.xhcl.common.core.controller.BaseController;
import com.xhcl.common.core.domain.AjaxResult;
import com.xhcl.common.core.domain.Stree;
import com.xhcl.common.core.page.TableDataInfo;
import com.xhcl.common.enums.BusinessType;
import com.xhcl.common.utils.StringUtils;
import com.xhcl.framework.uitls.poi.ExcelUtil;
import com.xhcl.system.domain.TGgPtdw;
import com.xhcl.system.service.ITGgPtdwService;

/**
 * 平台单位Controller
 * 
 * @author xhcl
 * @date 2020-08-25
 */
@Controller
@RequestMapping("/system/ptdw")
public class TGgPtdwController extends BaseController
{
    private String prefix = "system/ptdw";

    @Autowired
    private ITGgPtdwService tGgPtdwService;

    @RequiresPermissions("system:ptdw:view")
    @GetMapping()
    public String ptdw()
    {
        return prefix + "/ptdw";
    }

    /**
     * 查询平台单位树列表
     */
    @RequiresPermissions("system:ptdw:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGgPtdw tGgPtdw)
    { 
        
    	startPage();
        List<TGgPtdw> list = tGgPtdwService.selectTGgPtdwList(tGgPtdw);
    	return getDataTable(list);
    }

    /**
     * 导出平台单位列表
     */
    @RequiresPermissions("system:ptdw:export")
    @Log(title = "平台单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGgPtdw tGgPtdw)
    {
        List<TGgPtdw> list = tGgPtdwService.selectTGgPtdwList(tGgPtdw);
        ExcelUtil<TGgPtdw> util = new ExcelUtil<TGgPtdw>(TGgPtdw.class);
        return util.exportExcel(list, "ptdw");
    }

    /**
     * 新增平台单位
     */
    @GetMapping(value = { "/add/{dwbm}", "/add/" })
    public String add(@PathVariable(value = "dwbm", required = false) String dwbm, ModelMap mmap)
    {
        if (StringUtils.isNotNull(dwbm))
        {
            mmap.put("tGgPtdw", tGgPtdwService.selectTGgPtdwById(dwbm));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存平台单位
     */
    @RequiresPermissions("system:ptdw:add")
    @Log(title = "平台单位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGgPtdw tGgPtdw)
    {
        return toAjax(tGgPtdwService.insertTGgPtdw(tGgPtdw));
    }

    /**
     * 修改平台单位
     */
    @GetMapping("/edit/{dwbm}")
    public String edit(@PathVariable("dwbm") String dwbm, ModelMap mmap)
    {
        TGgPtdw tGgPtdw = tGgPtdwService.selectTGgPtdwById(dwbm);
        mmap.put("tGgPtdw", tGgPtdw);
        return prefix + "/edit";
    }

    /**
     * 修改保存平台单位
     */
    @RequiresPermissions("system:ptdw:edit")
    @Log(title = "平台单位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGgPtdw tGgPtdw)
    {
        return toAjax(tGgPtdwService.updateTGgPtdw(tGgPtdw));
    }

    /**
     * 删除
     */
    @RequiresPermissions("system:ptdw:remove")
    @Log(title = "平台单位", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{dwbm}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("dwbm") String dwbm)
    {
        return toAjax(tGgPtdwService.deleteTGgPtdwById(dwbm));
    }

    /**
     * 选择平台单位树
     */
    @GetMapping(value = { "/selectPtdwTree/{dwbm}", "/selectPtdwTree/" })
    public String selectPtdwTree(@PathVariable(value = "dwbm", required = false) String dwbm, ModelMap mmap)
    {
        if (StringUtils.isNotNull(dwbm))
        {
            mmap.put("tGgPtdw", tGgPtdwService.selectTGgPtdwById(dwbm));
        }
        return prefix + "/tree";
    }

    /**
     * 加载平台单位树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Stree> treeData()
    {
        List<Stree> ztrees = tGgPtdwService.selectTGgPtdwTree();
        return ztrees;
    }
}
